import { service } from './http';
import type { AxiosConfig } from '@/utils/global';
interface IResponse<T> {
  code: number;
  data: T;
  message: string;
  success: boolean;
}

// 提供默认的请求方法
export default {
  get: <T>(option: AxiosConfig): Promise<IResponse<T>> => {
    return service.request({ method: 'get', ...option }) as Promise<
      IResponse<T>
    >;
  },
  post: <T>(option: AxiosConfig): Promise<IResponse<T>> => {
    return service.request({ method: 'post', ...option }) as Promise<
      IResponse<T>
    >;
  },
  delete: <T>(option: AxiosConfig): Promise<IResponse<T>> => {
    return service.request({ method: 'delete', ...option }) as Promise<
      IResponse<T>
    >;
  },
  put: <T>(option: AxiosConfig): Promise<IResponse<T>> => {
    return service.request({ method: 'put', ...option }) as Promise<
      IResponse<T>
    >;
  },
  cancelRequest: (url: string | string[]) => {
    return service.cancelRequest(url);
  },
  cancelAllRequest: () => {
    return service.cancelAllRequest();
  },
};
